package ntu.p2p.past.test;

import java.io.IOException;

import rice.p2p.commonapi.rawserialization.InputBuffer;
import rice.p2p.commonapi.rawserialization.OutputBuffer;
import ntu.p2p.past.messaging.ObjectDifference;

public class Diff implements ObjectDifference {

	String content;
	
	protected Diff(InputBuffer buf) {
		try {
			int length = buf.readInt();
			byte[] temp = new byte[length];
			buf.read(temp, 0, length);
			this.content = new String(temp);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
	public Diff(String string) {
		this.content = string;
	}

	@Override
	public void serialize(OutputBuffer buf) throws IOException {
		byte[] temp = content.getBytes();
		buf.writeInt(temp.length);
		buf.write(temp, 0, temp.length);
	}

	public static ObjectDifference build(InputBuffer buf) {
		return new Diff(buf);
	}

}
